package src.mock.tomcat;

import java.io.IOException;
import java.io.InputStream;

/**封装请求对象*/
public class MockRequest {
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    private String url;
    private String method;
    public MockRequest(InputStream inputStream) throws IOException {
        String httpRequest="";
        byte[] httpRequestBytes=new byte[1024];
        int length=0;
        StringBuffer buffer=new StringBuffer();
        if((length=inputStream.read(httpRequestBytes,0,httpRequestBytes.length))>0){
            buffer.append(new String(httpRequestBytes,0,httpRequestBytes.length));
        }
        //while((length=inputStream.read(httpRequestBytes,0,httpRequestBytes.length))>0){

        //}
        httpRequest=buffer.toString();
        System.out.println("http request"+"\n"+httpRequest);

        String httpHead=httpRequest.split("\n")[0];
        url=httpHead.split("\\s")[1];
        method=httpHead.split("\\s")[0];
        System.out.println(this);
    }
    @Override
    public String toString(){
        return new String("请求地址："+url+"\t"+"请求方法："+method);
    }

}
